﻿using System;
using System.Configuration;

namespace Hxsoft.AppV1
{
	public static class FCKeditor
	{
		private static readonly string BrowserUrl = ConfigurationManager.AppSettings["FCKeditor:BrowserUrl"];
		private static readonly string UploaderUrl = ConfigurationManager.AppSettings["FCKeditor:UploaderUrl"];


		/// <summary>
		/// 取得上传浏览地址。
		/// </summary>
		/// <param name="globalId">信息的全局标识。</param>
		/// <param name="infoType">信息的类别。</param>
		/// <returns>上传浏览地址。</returns>
		public static string GetBrowserUrl(Guid globalId, string infoType)
		{
			return BrowserUrl + "?GlobalID=" + globalId + "&InfoType=" + infoType;
		}
		/// <summary>
		/// 取得上传浏览地址。
		/// </summary>
		/// <param name="globalId"></param>
		/// <param name="infoType"></param>
		/// <param name="siteId"></param>
		/// <returns></returns>
		public static string GetBrowserUrl(Guid globalId, string infoType,int? siteId)
		{
			return BrowserUrl + "?GlobalID=" + globalId + "&InfoType=" + infoType + (siteId.HasValue ? "&SiteId=" + siteId : "");
		}

		/// <summary>
		/// 取得快速上传地址。
		/// </summary>
		/// <param name="globalId">信息的全局标识。</param>
		/// <param name="infoType">信息的类别。</param>
		/// <returns>上传浏览地址。</returns>
		public static string GetUploaderUrl(Guid globalId, string infoType)
		{
			return UploaderUrl + "?GlobalID=" + globalId + "&InfoType=" + infoType;
		}

		/// <summary>
		/// 取得快速上传地址。
		/// </summary>
		/// <param name="globalId"></param>
		/// <param name="infoType"></param>
		/// <param name="siteId"></param>
		/// <returns></returns>
		public static string GetUploaderUrl(Guid globalId, string infoType, int? siteId)
		{
			return UploaderUrl + "?GlobalID=" + globalId + "&InfoType=" + infoType + (siteId.HasValue ? "&SiteId=" + siteId : "");
		}


		/// <summary>
		/// 为编辑器绑定上传地址。
		/// </summary>
		/// <param name="editor">要进行绑定的编辑器。</param>
		/// <param name="globalId">信息的全局标识。</param>
		/// <param name="infoType">信息的类别。</param>
		public static void BindUploadUrl(FredCK.FCKeditorV2.FCKeditor editor, Guid globalId, string infoType)
		{
			string browserUrl = GetBrowserUrl(globalId, infoType);
			string uploaderUrl = GetUploaderUrl(globalId, infoType);

			editor.LinkBrowserURL = browserUrl;
			editor.ImageBrowserURL = browserUrl;
			editor.FlashBrowserURL = browserUrl;

			editor.LinkUploadURL = uploaderUrl;
			editor.ImageUploadURL = uploaderUrl;
			editor.FlashUploadURL = uploaderUrl;
		}

		/// <summary>
		/// 为编辑器绑定上传地址。
		/// </summary>
		/// <param name="editor"></param>
		/// <param name="globalId"></param>
		/// <param name="infoType"></param>
		/// <param name="siteId"></param>
		public static void BindUploadUrl(FredCK.FCKeditorV2.FCKeditor editor, Guid globalId, string infoType,int? siteId)
		{
			string browserUrl = GetBrowserUrl(globalId, infoType, siteId);
			string uploaderUrl = GetUploaderUrl(globalId, infoType, siteId);

			editor.LinkBrowserURL = browserUrl;
			editor.ImageBrowserURL = browserUrl;
			editor.FlashBrowserURL = browserUrl;

			editor.LinkUploadURL = uploaderUrl;
			editor.ImageUploadURL = uploaderUrl;
			editor.FlashUploadURL = uploaderUrl;
		}
	}
}
